package com.example.xd.tuiliu_test.videoplayer.sample;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

import com.example.xd.tuiliu_test.R;
import com.example.xd.tuiliu_test.videoplayer.model.VideoModel;
import com.example.xd.tuiliu_test.videoplayer.widget.GeneralPlayerView;


public class Sample2Activity extends AppCompatActivity {
    private GeneralPlayerView playerView;
    boolean isFull;

    //"http://vfx.mtime.cn/Video/2018/06/29/mp4/180629124637890547.mp4"
    public static String rtmpUrl = "rtmp://10.1.120.224/tuiliu_test/test";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.player_sample_main2);
        playerView = findViewById(R.id.player_view);
        playerView.getVideoPicImageView().setImageResource(R.drawable.pic);//设置首帧
//        VideoModel videoModel = new VideoModel(Constance.https_path, "标清");
        VideoModel videoModel = new VideoModel(rtmpUrl, "标清");
        videoModel.autoPlay = true;//设置完播放源后是否自动播放
        videoModel.autoPlayWithLastPlayer = true;//是否自动和上一个playerview 续播
        playerView.setVideoModel(videoModel);
        playerView.setFullScreenListener(new GeneralPlayerView.FullScreenListener() {
            @Override
            public void fullScreen() {
                isFull = true;
            }

            @Override
            public void exitFullScreen() {
                isFull = false;
            }
        });
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (isFull) {
                playerView.exitFullScreen();
                return true;
            }
            return super.onKeyUp(keyCode, event);
        }
        return super.onKeyUp(keyCode, event);
    }


}
